package com.springcloud.controller;

import com.alibaba.fastjson.JSON;
import com.springcloud.entity.JobInfo;
import com.springcloud.service.JobInfoService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (JobInfo)表控制层
 *
 * @author xiaolei
 * @since 2020-01-27 14:33:31
 */
@RestController
@RefreshScope
public class JobInfoController {
    /**
     * 服务对象
     */
    @Resource
    private JobInfoService jobInfoService;


    @Value("${yyb.name}")
    private String name;

    @RequestMapping("/getValue")
    public String getValue() {
        return name;
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public JobInfo selectOne(Long id) {
        return this.jobInfoService.queryById(id);
    }

    @GetMapping("/query")
    public ResponseEntity<List<JobInfo>> selectOne2(Long id) {

        return  ResponseEntity.ok(this.jobInfoService.queryAll( new JobInfo()));
    }

    @GetMapping("/query2")
    public ResponseEntity<Object> selec3(int offset ,int limit) {
        List<JobInfo> jobInfos=jobInfoService.queryAllByLimit(offset,limit);

        if (jobInfos != null) {
            String jsonString = JSON.toJSONString(jobInfos);
            System.out.println(jsonString);
            return  ResponseEntity.ok(jobInfos);
        }
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
}